@extends('admin.layouts.header_other')
@section('title',"后台管理系统")
@section('content')
    <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
        <form class="layui-form" action="">
            <div class="amin-content">
                <div class="layui-row layui-col-space15">

                    <div class="layui-col-md12">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">分类名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" lay-verify="required|title" autocomplete="off" placeholder="分类名称" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="psort" lay-verify="required|psort" autocomplete="off" placeholder="排序" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">所属分类</label>
                                <div class="layui-input-inline">
                                    <select name="pid" lay-filter="aihao">
                                        <option value="0">顶级分类</option>
                                        @foreach($treeList as $cat)
                                            <optgroup label="{{$cat['title']}}">
                                                @foreach($cat['childer'] as $res)
                                                    <option value="{{$res['id']}}">{{$res['title']}}</option>
                                                @endforeach
                                            </optgroup>
                                            @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">是否发布</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="status" value="1" title="是" checked="">
                                    <input type="radio" name="status" value="2" title="否">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">分类描述</label>
                                <div class="layui-input-inline">
                                    <textarea placeholder="请输入内容"  name="description" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden"  name="_token" value="{{csrf_token()}}">
                                <button class="layui-btn" lay-submit="" lay-filter="downloadcat">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    </div>
    <script src="{{asset('attach/js/layui.js')}}"></script>
    <script>
        layui.use(['form','layer'],function () {
            var form = layui.form,
                $ = layui.$;
            form.on('submit(downloadcat)',function (data) {
                var index = parent.layer.getFrameIndex(window.name);
                var url='{{route('admin.downloadcat.addsave')}}',
                    data=$(data.form).serialize();
                $.ajax({
                    type:'POST',
                    url:url,
                    data:data,
                    success:function (data) {
                        if(data.code==200){
                            layer.msg(data.msg,{
                                icon:6,
                                time:2000
                            },function () {
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                        }else{
                            layer.msg(data.msg,{icon:5});
                            return;
                        }
                    },
                    complete:function () {
                        layer.close(this.layerIndex)
                    }
                })
                return false;
            })

        });

    </script>

@endsection
